{{define "script"}}
<!-- [ Layout wrapper] End -->
<!-- Core scripts -->
<script src="/assets/js/vendor.js"></script>

<!-- Demo -->
<script src="/assets/js/script.js"></script>
<!--<script src="/assets/js/jquery-3.5.1.min.js"></script>-->
<script src="/assets/libs/moment/moment.js"></script>
<script src="/assets/libs/bootstrap-daterangepicker/bootstrap-daterangepicker.js"></script>
<script src="/assets/libs/growl/growl.js"></script>
<script src="/assets/libs/bootbox/bootbox.js"></script>
<script src="/assets/libs/bootbox/bootbox.locales.js"></script>
<script src="/assets/libs/spin/spin.js"></script>
<script src="/assets/libs/ladda/ladda.js"></script>
<script src="/assets/libs/bootstrap-sweetalert/bootstrap-sweetalert.js"></script>
<script>
    const month_name = [
        "一月",
        "二月",
        "三月",
        "四月",
        "五月",
        "六月",
        "七月",
        "八月",
        "九月",
        "十月",
        "十一月",
        "十二月",
    ];
    $(function (){
        if($('#create_date_range').length>0){
            // Filters
            $('#create_date_range').daterangepicker({
                autoUpdateInput: false,
                locale: {
                    cancelLabel: '清除',
                    format: 'YYYY-MM-DD',
                    applyLabel:'确认',
                    monthNames:month_name
                }
            });

            $('#create_date_range').on('apply.daterangepicker', function(ev, picker) {
                $(this).val(picker.startDate.format('YYYY-MM-DD') + ' - ' + picker.endDate.format('YYYY-MM-DD'));
            });

            $('#create_date_range').on('cancel.daterangepicker', function(ev, picker) {
                $(this).val('');
            });
        }

        $("table").on("click","[name=checkBox1]",function (e){
            getCheckAllStatus()
        })
    })
    function getCheckAllStatus(){
        let result = true
        $("[name=checkBox1]").each(function (i,item){
            if(!$(item).prop("checked")){
                result = false
            }
        })
        $("[name=check_all]").prop("checked",result)
    }
    // $("body").on("click","tbody tr td",function (e){
    //     if(e.currentTarget._DT_CellIndex.column>0){
    //         $(this).parents("tr").find("[name=checkBox1]").prop("checked",!$(this).parents("tr").find("[name=checkBox1]").prop("checked"))
    //         getCheckAllStatus()
    //     }
    // })
    function checkAll(obj){
        let checked = $(obj).prop("checked")
        let index = $(obj).parent().index()
        if($(obj).parents(".dataTables_scroll").length>0){
            $(obj).parents(".dataTables_scroll").find(".dataTables_scrollBody").find("tbody>tr").each(function (i,item){
                $(item).find("td").eq(index).find('[type=checkbox]').prop("checked",checked)
            })
        }else{
            $(obj).parents("table").find("tbody>tr").each(function (i,item){
                $(item).find("td").eq(index).find('[type=checkbox]').prop("checked",checked)
            })
        }
    }
</script>
{{end}}